package greedyAlgorithm;

//https://leetcode.cn/problems/can-place-flowers/
public class CanPlaceFlowers {
    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        int i = 0;
        while (i < flowerbed.length && 0 < n) {
            // 10
            if (flowerbed[i] == 1) {
                i = i + 2;
            } else if (i == flowerbed.length - 1 || flowerbed[i + 1] == 0) { //  0 ||00
                i = i + 2;
                n--;
            } else {
                i = i + 3;
            }

        }
        return n <= 0;
    }
}

